import {
  tradeAccuracy
} from '@/utils/common';
export default {
  data() {
    return {
      hash: '',
      txNotFound: false,
      trade: {
        state: '',
        tx: {}
      },
      markdownTxt: ''
    }
  },
  watch: {
    $route() {
      this.init()
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      if (this.$route.query.hash) {
        this.hash = this.$route.query.hash
        this.getTradeDetail(this.hash)
      } else {
        this.$notify({
          title: this.$t('components.tip'),
          message: this.$t('components.errParam'),
          type: "warning",
          duration: 1000
        });
        this.$router.push({
          path: "/"
        });
      }
    },
    getTradeDetail(hash) {
      this.Rpc.queryTransaction(hash).then((data) => {
        if (!data.result) {
          // 未查询到交易信息
          this.txNotFound = true
          return
        }
        this.trade = data.result;
        if (tradeAccuracy(data.result.tx.execer, data.result.receipt.ty, this.$store.getters.isParallelChain)) {
          this.trade.state = 2
          this.trade.txt = this.$store.getters.isParallelChain ? this.$t('txDetail.faild') : this.$t('components.fail')
        } else {
          this.trade.state = 1
          this.trade.txt = this.$store.getters.isParallelChain ? this.$t('txDetail.success') : this.$t('components.succ');
        }
        // data.result.tx.nonce = data.result.tx.nonce.toString();
        // this.tradehInfoTx = data.result.tx;
        if (this.trade.tx.execer == 'user.write') {
          this.markdownTxt = this.trade.tx.payload.content;
          this.$forceUpdate()
        }
      });
    },
    success() {
      this.$message.success(this.$t('components.copySuc'));
    },
    error() {
      this.$message.warning(this.$t('components.copyErr'));
    }
  }
};